<template>
  <div class="page-wrapper">
    <div class="mian-content">
      <div class="i-swipeout-demo-item" :operateWidth="50" v-for="(item,index) in collectionList" :key="index">
          <div slot="content" style="width:20rem">
            <div class="item">
              <router-link class="item-info" to="">
                <div class="item-img">
                  <img class="img" :src="item.picUrl" mode="aspectFill"/>
                </div>
                <div class="item-title">
                  <div class="title">{{item.productName}}</div>
                </div>
              </router-link>
              <div class="del-btn" @click="deleteCollection(item.collectId)">
                删除
              </div>  
            </div>
          </div>
      </div>
    </div>
  </div>
</template>
<script>
import { API } from '../../config'
export default {
  name:'CollectList',
  data() {
    return {
      collectionList: [],
      pageNum: 1,
      isLoading: false,
      pageSize:10,
      // collectId:''
    }
  },
  methods: {
    /**
     * 收藏列表
     */
    getList (pageNum) {
      let params
      params = pageNum ? pageNum : this.pageNum
      let vm = this
      let accesstoken = vm.getLocalStorage('accesstoken')
      vm.$axios.get(API + '/user/collect/list/'+params+'/'+vm.pageSize,{
          headers: {'accesstoken': accesstoken}//设置header信息
        }).then((response) => {
        if (response.data.code === 200) {
          vm.collectionList = response.data.data.data
        } else {
          vm.$message(response.data.msg)
        }
      })
    },
    /**
     * 删除收藏
     */
    deleteCollection (collectId) {
      let vm = this
      let accesstoken = vm.getLocalStorage('accesstoken')
      vm.$axios.get(API + '/user/collect/del/'+collectId,{
          headers: {'accesstoken': accesstoken}//设置header信息
        }).then((response) => {
        if (response.data.code === 200) {
            vm.$message('删除成功')
            this.getList();
        } else {
          vm.$message(response.data.msg)
        }
      })
    }
  },
  mounted(){
    let vm = this
    vm.getList()
  }
}
</script>

<style lang='less'>
@import '../../css/user/collectList.less';
</style>